package org.maverickjs.web.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.maverick.persistence.simple.jpa.ManagerFactory;

@WebListener
public class ApplicationListener implements ServletContextListener {

    public ApplicationListener() {
        
    }

    public void contextInitialized(ServletContextEvent arg0) {
    	System.out.println("------------------------------------------------------------------------");
    	System.out.println("--|| Starting application MaverickJS .................... ");
    	System.out.println("------------------------------------------------------------------------");
    	System.out.println("Persistence is Open? -> " + ManagerFactory.currentManagerFactory().createEntityManager().isOpen());
    	System.out.println("------------------------------------------------------------------------");
    	System.out.println("--|| Starting sucess............................................... ");
    	System.out.println("------------------------------------------------------------------------");
    }

	
    public void contextDestroyed(ServletContextEvent arg0) {
    	System.out.println("------------------------------------------------------------------------");
    	System.out.println("--|| Stopping application CondominioJavaWebIII.................... ");
    	System.out.println("------------------------------------------------------------------------");
    	ManagerFactory.currentManagerFactory().close();
    	System.out.println("------------------------------------------------------------------------");
    	System.out.println("--|| Stopping sucess............................................... ");
    	System.out.println("------------------------------------------------------------------------");
    }
	
}